#include "album.h"

model::album::album(const model::dom &node)
{
	parse(node);
}

void model::album::parse(const model::dom &node)
{
	_titles.clear();
	_name = node.find_attrib("name");
	boost::shared_ptr<model::dom> ptr(
		node.find("title"));
	while(*ptr) {
		_titles.push_back(model::title(*ptr));
		ptr = ptr->next_tag();
	}
}

void model::album::print() const
{
	cout << "Album: " << _name << endl;
	for(list<model::title>::const_iterator i = _titles.begin(); 
	    i != _titles.end(); ++i) {
		i->print();
	}
}

string model::album::to_xml() const
{
	string tmp = "<album name=\"" + _name + "\">";
	typedef list<model::title>::const_iterator it;
	for(it i = _titles.begin(); i != _titles.end(); ++i) {
		tmp += i->to_xml();
	}
	tmp += "</album>";
	return tmp;
}

